package FlowGram.Application.Parser.Utility;

import java.util.Hashtable;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;


/**
 * 
 * @author thackray
 *
 */
public class Configuration {
	
	protected static Hashtable<String, Configuration> instances = new Hashtable<String, Configuration>();
	protected static String defaultConfig;
	
	public XMLConfiguration config;
	
	protected Configuration(String filename) throws Exception{
		try {
			this.config = new XMLConfiguration(filename);
		} catch (ConfigurationException e) {
			throw new Exception("Unable to load configuration!\n"+e.getMessage());
		}
	}
	protected Configuration(){
		
	}
	public static void setDefault(String deflt){
		defaultConfig = deflt;
	}
	public static Configuration getInstance(String config) throws Exception{
		if(!instances.containsKey(config)){
			instances.put(config, new Configuration(config));
		}
		return instances.get(config);
	}
	public static Configuration getInstance() throws Exception{
		if(defaultConfig != null){
			return getInstance(defaultConfig);
		}
		throw new Exception("There is no default configuration!");
	}
	
}
